trigger trgOnUpdateEntitlement on Entitlement__c (before update) {
    if (!DefEntCrossTrigger.InEntUpdateTrigger) 
    {
        DefEntCrossTrigger.InEntUpdateTrigger = true;
        
        System.assertEquals(0,DefEntCrossTrigger.DirtySPs.size(),'Reentrance detected');
        for(Entitlement__c e:trigger.new) {
        
                if (e.Case_Pack__c==True) { 
                    if (e.Renewal_Amount__c==null) e.Renewal_Amount__c = 0; 
                } else { 
                    if (e.Renewal_Amount__c==0) e.Renewal_Amount__c = null; 
                } 
            
            if (e.IsDefault__c==true) {
          
                if (!DefEntCrossTrigger.DirtySPs.contains(e.Support_Program__c)) {
                    DefEntCrossTrigger.DirtySPs.add(e.Support_Program__c);
                    List<Entitlement__c> eCurrDefArr = new List<Entitlement__c>();
                    for(Entitlement__c eCurrDef : [Select Id,IsDefault__c From Entitlement__c Where IsDefault__c=true And Support_Program__c=:e.Support_Program__c And Id<>:e.Id]) {
                        eCurrDef.IsDefault__c = false;
                        eCurrDefArr.add(eCurrDef);
                        System.assertNotEquals(null,e.Support_Program__c,'Entitlement.SP can never be null');
                    }
                    
                    // InEntUpdateTrigger flag is what stops infinite loop
                    update eCurrDefArr;
                } else {
                    e.IsDefault__c=false;
                }
            }
        }
        
        DefEntCrossTrigger.InEntUpdateTrigger = false;
    }
}